﻿@using Entidades.Sistema.Distribucion.CoR;
@{
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();

    var grid = Html.DevExpress().GridView(
        settings =>
        {
            settings.Name = "gvEditing";
            settings.KeyFieldName = "IdVehiculo";
            settings.CallbackRouteValues = new { Controller = "Vehiculo", Action = "EditVehiculoPartial" };
            settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Vehiculo", Action = "EditVehiculoAddNewPartial" };
            settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Vehiculo", Action = "EditVehiculoUpdatePartial" };
            settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Vehiculo", Action = "EditVehiculoDeletePartial" };
            settings.SettingsEditing.Mode = GridViewEditingMode.PopupEditForm;
            
            
            settings.SettingsBehavior.ConfirmDelete = true;
            settings.SettingsPopup.EditForm.Width = 600;
            settings.SettingsPopup.EditForm.HorizontalAlign = PopupHorizontalAlign.Center;
            settings.SettingsPopup.EditForm.VerticalAlign = PopupVerticalAlign.WindowCenter;
            settings.SettingsPager.FirstPageButton.Visible = true;
            settings.SettingsPager.LastPageButton.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50" };
            
            
            settings.Settings.ShowFilterRow = true;
            settings.Settings.ShowFilterRowMenu = true;
            settings.CommandColumn.Visible = true;
            settings.CommandColumn.ShowClearFilterButton = true;
            
            settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);

            settings.CommandColumn.Visible = true;
            //settings.CommandColumn.ShowNewButtonInHeader = ViewBag.PermisoCreate;
            //settings.CommandColumn.ShowEditButton = ViewBag.PermisoEdit;
            //settings.CommandColumn.ShowDeleteButton = ViewBag.PermisoDelete;

            settings.CommandColumn.ShowNewButtonInHeader = true;
            settings.CommandColumn.ShowEditButton = true;
            settings.CommandColumn.ShowDeleteButton = true;
            
            settings.Columns.Add(column =>
            {
                column.FieldName = "IdVehiculo";
                column.Caption = "IdVehiculo";
                column.Visible = false;;
            });               
                
            settings.Columns.Add("Marca");
            settings.Columns.Add("Modelo");
            settings.Columns.Add("Dominio");

            settings.Columns.Add(column =>
            {
                column.FieldName = "FechaAdquisicion";
                column.Caption = "Fecha Adquisicion";
                column.ColumnType = MVCxGridViewColumnType.DateEdit;
                column.PropertiesEdit.DisplayFormatString = "dd/MM/yyyy";
            });
            settings.Columns.Add(
                column =>
                {
                    column.FieldName = "TipoServicioDespacho";
                    column.Caption = "Tipo Servicio";
                    column.Width = 80;
                    column.ColumnType = MVCxGridViewColumnType.ComboBox;
                    var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                    comboBoxProperties.DataSource = ViewBag.TipoServicioDespacho;
                    comboBoxProperties.ValueType = typeof(EnumTipoServicioDespacho);
                    comboBoxProperties.DropDownStyle = DropDownStyle.DropDown;
                });            
            
            settings.PreRender = (s, e) =>
            {
                var sender = (MVCxGridView)s;
                sender.FocusedRowIndex = 1;
            };

            settings.SettingsBehavior.AllowFocusedRow = true;
            
        });

    if (ViewData["EditError"] != null){
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}

@grid.Bind(Model).GetHtml()






